package leecode

func checkInclusion(s1 string, s2 string) bool {
	if len(s1) > len(s2) {
		return false
	}
	s1Arr, s2Arr := [26]uint16{}, [26]uint16{}

	//初始化
	for i := 0; i < len(s1); i++ {
		s1Arr[s1[i]-'a']++
		s2Arr[s2[i]-'a']++
	}
	if s1Arr == s2Arr {
		return true
	}
	for right := 1; right <= len(s2)-len(s1); right++ {
		s2Arr[s2[right-1]-'a']--
		s2Arr[s2[right+len(s1)-1]-'a']++
		if s2Arr == s1Arr {
			return true
		}
	}
	return false
}
